import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
import { createSelectors } from "../utils/createSelectors";

// createSelectors接受store作为参数，返回的store会增加use property
export const useCatStore = createSelectors(create(
  immer((set, get) => ({
    cats: {
      bigCats: 0,
      smallCats: 0,
    },
    increaseBigCats: () =>
      set((state) => {
        state.cats.bigCats++
      }),
    increaseSmallCats: () =>
      set((state) => {
        state.cats.smallCats++
      }),
    summary: () => {
        const total = get().cats.bigCats + get().cats.smallCats
        return `There are ${total} cats in total`
    }
  }))
))
